import { continuousDeploymentApi } from '@choerodon/master';

export default ({ pipelineId }:
   {pipelineId:string | undefined}): object => ({
  autoCreate: true,
  fields: [
    {
      name: 'name',
      label: '部署流程名称',
      required: true,
      maxLength: 30,
      validator: async (value:string) => {
        const paramsObj = { name: value };
        if (pipelineId) {
          Object.assign(paramsObj, { id: pipelineId });
        }
        const res = await continuousDeploymentApi.checkDeploymentProcessName(paramsObj);
        if (!res) {
          return '部署流程名称在当前项目下已存在';
        }
        return true;
      },
    },
    {
      name: 'token',
      label: '令牌',
      required: true,
    },
    {
      name: 'appVersionTriggerEnable',
      label: '应用服务版本生成触发',
      type: 'boolean' as any,
      defaultValue: true,
    },
  ],
});
